#include "head.h"

void onePath(const char* arg,char* onepath,stack1_t* dir){
    char buf[4096]={0};
    printf("%c\n",arg[0]);
    printf("%c\n",arg[1]);
    printf("%c\n",arg[2]);
    if(arg[0]=='.'){
        if(arg[1]=='.'){//回退到上一级
            travel_stack(*dir,buf);
            printf("onepath .. :%s\n",buf);
            if(dir->stacksize==1){
                strcpy(onepath,buf);
                return;
            }
            printf("onepath 16\n");
            int endsize=strlen(dir->top->data);
            printf("topdata :%s topdatasize: %ld\n",dir->top->data,strlen(dir->top->data));
            int buflen=strlen(buf);
            printf("buflen: %ld\n",strlen(buf));
            char path[4096]={0};

            strncpy(path,buf,buflen-endsize-1);
            printf("%s:\n",path);
            strcat(path,&arg[3]);
            printf("%s:\n",path);
            strcpy(onepath,path);
        }
        else if(arg[1]=='/'){
            travel_stack(*dir,buf);
            if(arg[2]!='\0'){
                strcat(buf,"/");
            }
            strcat(buf,&arg[2]);
            strcpy(onepath,buf);
        }
        else{
            travel_stack(*dir,buf);
            strcpy(onepath,buf);
        }
    }
    else if(arg[0]=='/'){
        char path[4096]={0};
        strcpy(path,dir->bottom->data);
        strcat(path,&arg[0]);
        strcpy(onepath,path);
    }
    else if(arg[0]=='\0'){
        travel_stack(*dir,buf);
        strcpy(onepath,buf);
    }
    else{
        travel_stack(*dir,buf);
        printf("%s\n",buf);
        strcat(buf,&arg[0]);
        strcpy(onepath,buf);
    }
}
